package com.fitso.model.bean;

import java.io.Serializable;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

public class User extends ModelBean implements Comparable<User>, Serializable {
	// Only change on breaking changes, i.e., removing fields
	private static final long serialVersionUID = 1L;
	
	private String _email, _password, _firstName, _lastName;

	public User() {}

	public User(String firstName, String lastName, String email, String password) {
		_firstName = firstName;
		_lastName = lastName;
		_email = email;
		_password = password;
	}

	/**
	 * Notice that the password is not part of the comparison since it can be in
	 * the open or encrypted but still be the same
	 */
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (o == this) {
			return true;
		}
		if (o.getClass() != getClass()) {
			return false;
		}

		User other = (User) o;
		return new EqualsBuilder().append(_email, other._email).append(_firstName, other._firstName).append(_lastName,
				other._lastName).isEquals();
	}

	public String getEmail() {
		return _email;
	}

	public String getFirstName() {
		return _firstName;
	}

	public String getLastName() {
		return _lastName;
	}

	public String getPassword() {
		return _password;
	}

	public int hashCode() {
		return new HashCodeBuilder().append(_email).append(_firstName).append(_lastName).toHashCode();
	}

	public void setEmail(String email) {
		_email = email;
	}

	public void setFirstName(String firstName) {
		_firstName = firstName;
	}

	public void setLastName(String lastName) {
		_lastName = lastName;
	}

	public void setPassword(String password) {
		_password = password;
	}

	public String toString() {
		return new ReflectionToStringBuilder(this).toString();
	}

	public int compareTo(User other) {
		return new CompareToBuilder().append(_lastName, other._lastName).append(_firstName, other._firstName).append(
				_email, other._email).toComparison();
	}
}
